package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.CustomerFollowRecordsDAO;
import com.zerosky.crm.po.CustomerFollowRecords;
import com.zerosky.crm.service.CustomerFollowRecordsService;
import com.zerosky.crm.util.PageInfo;

/**
 * Customerfollowrecords业务逻辑实现类
 * 
 * @author hugy;
 * @since 2017-06-08
 *
 */
@Service(value="customerFollowRecordsService")
public class CustomerFollowRecordsServiceImpl implements CustomerFollowRecordsService {

	@Autowired
	private CustomerFollowRecordsDAO customerFollowRecordsDAO; // Customerfollowrecords数据接口

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<CustomerFollowRecords> getCustomerFollowRecordsList(Map map) {
		return customerFollowRecordsDAO.getCustomerFollowRecordsList(map);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public CustomerFollowRecords getCustomerFollowRecordsById(String id) {
		return customerFollowRecordsDAO.getCustomerFollowRecordsById(id);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void saveCustomerFollowRecords(CustomerFollowRecords customerFollowRecords, String operation)
			throws Exception {
		if ("新增".equalsIgnoreCase(operation)) {
			customerFollowRecordsDAO.addCustomerFollowRecords(customerFollowRecords);
		} else if ("修改".equalsIgnoreCase(operation)) {
			customerFollowRecordsDAO.updateCustomerFollowRecords(customerFollowRecords);
		}
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void deleteCustomerFollowRecordsById(String id) throws Exception {
		customerFollowRecordsDAO.deleteCustomerFollowRecordsById(id);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<CustomerFollowRecords> getCustomerFollowPageInfoList(Map map,
			PageInfo<CustomerFollowRecords> page) {
		int begin = ((page.getPageNo() - 1) * page.getPageSize());
		int pageSize = page.getPageSize();

		// 写入数据
		map.put("pageNo", begin);
		map.put("pageSize", pageSize);
		List<CustomerFollowRecords> list = customerFollowRecordsDAO.getCustomerFollowRecordsList(map);
		page.setList(list);

		int count = customerFollowRecordsDAO.countCustomerFollowRecords(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

}
